package com.torry.workflow.service.wo.utils;

import com.torry.workflow.service.wo.events.ProcessEventHandler;
import org.kie.api.runtime.KieContainer;
import org.kie.api.runtime.KieSession;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

@Component
public class DroolsUtil {
    @Resource
    private KieContainer kieContainer;
    @Resource
    private ProcessEventHandler eventHandler;

    public void executeRules(Object... objs) {
        KieSession kieSession = kieContainer.newKieSession();
        kieSession.setGlobal("eventHandler", eventHandler);

        for (Object obj : objs) {
            kieSession.insert(obj);
        }
        kieSession.fireAllRules();
        kieSession.dispose();
    }
}
